#include <stdio.h>
#include <stdlib.h>

#include "gpaCalcStub.h"
#include "fileControl.h"

float calculateGPA(char studentID[])
{

    int x, numModules; //x is counter variable, variable for the number of modules
    float gps[MAX_NUM_MODULES]; //Grade point score array.
    float gpv[MAX_NUM_MODULES]; //grade point value array.
    float gpa = 0;

    float totalGPS, totalCredits=0;

    numModules = getNumModules(); // Calls the function getnummodules which populates the variable nummodules with the number of modules.
    getGrades(studentID);

    for(x=1;x<=numModules;x++) // From grades this finds out the grade point value of each grade assuming that the inputted grades are correct.
    {

       if(grades[x]<=34)
       {
           gpv[x]=0.00;
       }
       else if(grades[x]<=39)
       {
           gpv[x]=1.50;
       }
       else if(grades[x]<=49)
       {
           gpv[x]=2.00;
       }
       else if(grades[x]<=54)
       {
           gpv[x]=2.50;
       }
       else if(grades[x]<=59)
       {
           gpv[x]=2.75;
       }
       else if(grades[x]<=69)
       {
           gpv[x]=3.00;
       }
       else if(grades[x]<=79)
       {
           gpv[x]=3.50;
       }
       else if(grades[x]<=100)
       {
           gpv[x]=4.00;
       }
    }
    //code that adds up the total credits.
    for(x=1;x<=numModules;x++)
    {
        totalCredits=totalCredits+credits[x]; // Adds up to find the total credits of a student
    }

    for(x=1;x<numModules;x++)
    {
     gps[x]=gpv[x]*credits[x]; // works out the Grade point scores
    }

    for(x=1;x<numModules;x++)
    {
        totalGPS=totalGPS+gps[x]; // adds up the total Grade Point Score
    }

    gpa=totalGPS/totalCredits; // Divides total grade point score by total credits to give GPA


    return gpa;

}








